package myJqueryOne.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

import myJqueryOne.service.BranchService;
import myJqueryOne.service.impl.BranchServiceImpl;

public class BranchServlet extends HttpServlet {
	private static ObjectMapper mapper = new ObjectMapper();
	static BranchService branchService=new BranchServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String method=req.getParameter("method");
		if("list".equals(method)) {
			list(req,resp);
		}
	}
	private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String cityCode=req.getParameter("cityCode");
		PrintWriter out=resp.getWriter();
		out.println(mapper.writeValueAsString(branchService.listAll(cityCode)));
	}
}
